//diag_log format["Setting up fnc_begin_nomatch"];
//fnc_begin_noMatch = {
	[] spawn {

		if !(isDedicated) then {
			/* Is run when a match is not running. Give players ability to buy shit  */
			player setPos ([] call fnc_get_spawnPos);
			[] call fnc_show_buyMenu;

			/* Watcher thread to re-start the buy menu if a dialog has been closed for too long */
			[] spawn {
				while { !matchInProgress} do {
					waitUntil { !dialog };

					_time = time;
					_diagOk = false;
					for "_x" from 1 to 5 do {
						if (dialog) then {
							_diagOk = true;
						};
						sleep 0.1;
					};

					if (!(_diagOk) and !(matchInProgress)) then {
						[] call fnc_show_buyMenu;
					};
				};
			};

			/* Nothing more to do really, perhaps lock player position.. Other than that wait for server to give the green light */
		};

		deleteMarkerLocal "BOMB";
		deleteMarkerLocal "WESTSPAWN";

		if (isServer) then {	
			/* Remove old bomb */
			deleteVehicle bomb;

			/* Remove the old game area marker */
			deleteMarker "currentarea";

			/* Already prepare the new spawn values here */
			[] call fnc_setup_match;
		
			_time = time;

			/* 1 minute buy time enough? */
			waitUntil { time > (_time + 20) };

			/* Start the game ! */
			matchInProgress = true;
			publicVariable "matchInProgress";


			/* Create the game area marker here */
			_markerSize = ((positions select currentPosition) select 4);  /* x,y,angle */	

			_currentarea = createMarker ["currentarea", ((positions select currentPosition) select 3)];
			_currentarea setMarkerSize [_markerSize select 0, _markerSize select 1];
			_currentarea setMarkerDir (_markerSize select 2);
			_currentarea setMarkerShape "RECTANGLE";
			_currentarea setMarkerBrush "Solid";
			_currentarea setMarkerColor "ColorRed";
			_currentarea setMarkerAlpha 0.5;

			/* Dont forget to manually run the function here lulz */
			if !(isDedicated) then {
				Null = [] spawn fnc_begin_match;
			};


			/* Clean out dead bodies */
			[] call fnc_remove_dead;

			/* Create a time limit watcher thread */
			[] spawn {
				_time = time;

				scopeName "time_main";
				_nextNotify = 5*60;

				if (matchInProgress) then {
					while { time < (_time + (5*60)) } do {
						if !(matchInProgress) then {
							breakTo "time_main";
						};
			
						_timeNow = (time - _time);
						_timeLeft = (5*60) - _timeNow;

						if ((_timeLeft <= 60) and (_nextNotify > 60)) then {
							_nextNotify = 0;
							notify_timelimit = 60;
							publicVariable "notify_timelimit";
							(notify_timelimit) spawn fnc_notify_time;
						} else {
							if ((_timeLeft < (5*60)) and (_nextNotify > (5*60))) then {
								_lastNotify = 60;
								notify_timelimit = (5*60);
								publicVariable "notify_timelimit";
								(notify_timelimit) spawn fnc_notify_time;
							};
						};

						sleep 0.5;
					};

					if (matchInProgress) then {
						ROUND_WIN = 4;
						publicVariable "ROUND_WIN";
						[] call fnc_eh_win;
					};
				};

			};
		};
	};
//};